package com.diandi.signature.manager.impl.contract;

import com.diandi.signature.bean.contract.SignatureContract;
import com.diandi.signature.bean.pkgmsg.SignaturePlatformPkgMsg;
import com.diandi.signature.bean.proceessinfo.SignatureProcessDetail;
import com.diandi.signature.bean.proceessinfo.SignatureProcessLog;
import com.diandi.signature.enums.platfrom.BusinessStatus;
import com.diandi.signature.enums.platfrom.PassStatus;
import com.diandi.signature.enums.platfrom.PlatFormStatus;
import com.diandi.signature.enums.platfrom.ProcessFlag;
import com.diandi.signature.manager.contract.FddUploadContractManager;
import com.diandi.signature.mapper.SignaturePlatformPkgmsgMapper;
import com.diandi.signature.mapper.SignatureProcessDetailMapper;
import com.diandi.signature.mapper.SignatureProcessLogMapper;
import com.diandi.signature.utils.PackageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
* @author mwz
* @create 2017-08-31 17:20
* @version V1.0.0
* @description description
*/
@Component
public class FddUploadContractManagerImpl implements FddUploadContractManager {


    @Autowired
    SignatureProcessLogMapper signatureProcessLogMapper;
    @Autowired
    private SignatureProcessDetailMapper signatureProcessDetailMapper;
    @Autowired
    SignaturePlatformPkgmsgMapper signaturePlatformPkgmsgMapper;


    @Override
    public Map<String, String> FddUploadContract(Map<String, String> paramMap) {
        return null;
    }

    /**
     * 插入过程信息
     * 发送到通道消息
     * @param params
     * @return
     * @throws Exception
     */
    @Transactional
    @Override
    public boolean insertProcessInfoData(SignatureContract signatureContract, Map<String, String> params, Integer processFlag) throws Exception {

        /**2.1、插入状态主表数据*/
        SignatureProcessLog signatureProcessLog =  PackageParams.getInitSignatureProcessLogtPkgMsg( params );
        signatureProcessLog.setInterfaceType( processFlag );
        signatureProcessLogMapper.updateSignatureProcessLog( signatureProcessLog );

        /**2.2、插入状态明细数据*/
        SignatureProcessDetail signatureProcessDetail =  PackageParams.getSignatureProcessDetailPkgMsg( params );
        signatureProcessDetailMapper.insertSignatureProcessDetail(signatureProcessDetail);

      /*  *//**2.2、插入报文信息*//*

        params.put("requestMsg",params.toString());
        params.put("returnMsg","");
        params.put("unnotifyMsg","");
        SignaturePlatformPkgMsg signaturePlatformPkgMsg = PackageParams.getPlatFormPkgmsg( params );
        signaturePlatformPkgmsgMapper.insertSignaturePlatformPkgmsg( signaturePlatformPkgMsg );*/
        return false;
    }

    @Override
    public SignatureContract updateProcessInfoData(SignatureContract signatureContract, Map<String, String> params, Integer processFlag) throws Exception {

        /**2.1、更新状态主表数据*/
        SignatureContract contract = new SignatureContract();
        Map<String, String> queryParams = new HashMap<String,String>();
        queryParams.put("signatureCode",signatureContract.getSignatureCode() );
        queryParams.put("contractCode",signatureContract.getContractCode() );
        queryParams.put("userId",   String.valueOf( signatureContract.getUserId() ) );
        SignatureProcessLog  signatureProcessLog = signatureProcessLogMapper.getSignatureProcessLogByCode(queryParams);
        signatureProcessLog.setInterfaceType( processFlag );
        signatureProcessLog.setBusinessStatus(BusinessStatus.处理中.getStatus());
        signatureProcessLog.setPlatformStatus(PlatFormStatus.处理中.getStatus());
        signatureProcessLog.setPassStatus( PassStatus.待受理.getStatus());
        signatureProcessLog.setProcessFlag(ProcessFlag.处理中.getType() );
        signatureProcessLogMapper.updateSignatureProcessLog( signatureProcessLog );

        /**2.2、插入状态明细数据*/
        SignatureProcessDetail signatureProcessDetail =  PackageParams.getUpdateProcessDetailPkgMsg( params );
        signatureProcessDetailMapper.insertSignatureProcessDetail(signatureProcessDetail);


        /**2.2、插入报文信息*/

       /* params.put("requestMsg",params.toString());
        params.put("returnMsg",params.get("returnMsg"));
        params.put("unnotifyMsg","");
        SignaturePlatformPkgMsg signaturePlatformPkgMsg = PackageParams.getPlatFormPkgmsg( params );
        signaturePlatformPkgmsgMapper.insertSignaturePlatformPkgmsg( signaturePlatformPkgMsg );*/
        return contract;
    }
}
